// cf-119c
// run: $exec < input
// opt: 0
// flag: -g
#include <iostream>
#include <algorithm>
#include <stack>

int const maxn = 55;
int const maxd = 105;
int const inf = 1<<29;

struct data
{
	long long a, b, c, id;
};

data da[maxn];

long long f[maxn][maxn][maxd];
std::pair<int, int> from[maxn][maxn][maxd];
int n, m, k;

std::stack<std::pair<int, int>> ans;

void print(std::pair<int, int> x)
{
	for (int i = n; i > 0; x = from[i--][x.first][x.second])
		ans.push(x);
	for (; !ans.empty(); ans.pop()) {
		int i = ans.top().first;
		std::cout << da[i].id << ' ' << da[i].a + ans.top().second << '\n';
	}
}

int main()
{
	std::cin >> n >> m >> k;
	for (int i = 1; i <= m; i++) {
		std::cin >> da[i].a >> da[i].b >> da[i].c;
		da[i].id = i;
	}
	std::sort(da + 1, da + m + 1, [](data const & a, data const & b) {
				return a.c < b.c;
			});

	for (int i = 0; i <= n; i++)
		for (int j = 0; j <= m; j++)
			for (int t = 0; t <= k; t++) f[i][j][t] = -inf;

	for (int j = 1; j <= m - n + 1; j++)
		for (int t = 0; da[j].a + t <= da[j].b; t++)
			f[1][j][t] = t + da[j].a;

	for (int i = 2; i <= n; i++) {
		for (int j = 1; j <= m - (n - i); j++) {
			for (int t = 0; da[j].a + t <= da[j].b; t++) {
				for (int u = 1; u < j; u++) {
					if (da[j].c == da[u].c) continue;
					long long need = da[j].a + t - k;
					if (da[u].a <= need && need <= da[u].b) {
						need -= da[u].a;
						if (f[i - 1][u][need] > 0 && f[i][j][t] < f[i - 1][u][need] + da[j].a + t) {
							f[i][j][t] = f[i - 1][u][need] + da[j].a + t;
							from[i][j][t] = {u, need};
						}
					}

					need = da[j].a + t;
					if (need % k) continue;
					need /= k;
					if (da[u].a <= need && need <= da[u].b) {
						need -= da[u].a;
						if (f[i - 1][u][need] > 0 && f[i][j][t] < f[i - 1][u][need] + da[j].a + t) {
							f[i][j][t] = f[i - 1][u][need] + da[j].a + t;
							from[i][j][t] = {u, need};
						}
					}
				}
			}
		}
	}

	bool ok = false;
	long long max = -inf;
	int ti, tj;
	for (int i = 1; i <= m; i++)
		for (int t = 0; da[i].a + t <= da[i].b; t++) {
			if (f[n][i][t] > 0) {
				if (f[n][i][t] > max) {
					ok = true;
					max = f[n][i][t];
					ti = i; tj = t;
				}
			}
		}
	if (ok) {
		std::cout << "YES\n";
		print({ti, tj});
	} else
		std::cout << "NO\n";
}

